package leetcode;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * ClassName: XiaohoushuT3
 * Package: leetcode
 * Description:
 *
 * @Author wjn
 * @Create 2025/9/3 19:54
 * @Version 1.0
 */
public class XiaohoushuT3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = scanner.next();
        scanner.close();

        int count = 0;
        char[] chars = s.toCharArray();
        int len = chars.length;

        while (true){
            boolean[] marked = new boolean[len];
            boolean hasInteraction = false;

            for (int i = len - 2; i >= 0; i--) {
                if (chars[i] != chars[i + 1] && !marked[i + 1]) {
                    marked[i+1] = true;
                    hasInteraction = true;
                }
            }
            if (!hasInteraction) {
                break;
            }
            int newLen = 0;
            char[] newChars = new char[len];
            for (int i = 0; i < len; i++) {
                if (!marked[i]) {
                    newChars[newLen++] = chars[i];
                } else {
                    count++;
                }
            }
            chars = Arrays.copyOf(newChars, newLen);
            len = newLen;
            if (len <= 1) {
                break;
            }
        }
        System.out.println(count);
    }
}
